package org.clever.sharding.jdbc.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.clever.sharding.jdbc.annotation.Sharding;
import org.clever.sharding.jdbc.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 作者： lzw<br/>
 * 创建时间：2018-09-14 18:05 <br/>
 */
@Api(description = "测试")
@RequestMapping("/test")
@RestController
@Slf4j
public class TestController {
    @Autowired
    private TestService testService;

    @ApiOperation("只读")
    @GetMapping("/read")
    @Sharding
    public Object read() {
        return testService.read();
    }

    @ApiOperation("只写")
    @GetMapping("/write")
    @Sharding
    public Object write() {
        return testService.write();
    }

    @ApiOperation("先写在读")
    @GetMapping("/writeAndRead")
    @Sharding
    public Object writeAndRead() {
        return testService.writeAndRead();
    }

    @ApiOperation("先读在写")
    @GetMapping("/readAndWrite")
    @Sharding
    public Object readAndWrite() {
        return testService.readAndWrite();
    }

    @ApiOperation("写 - 读 - 写")
    @GetMapping("/writeAndReadAndWrite")
    @Sharding
    public Object writeAndReadAndWrite() {
        return testService.writeAndReadAndWrite();
    }

    @ApiOperation("写 - 读 - 读 - 写")
    @GetMapping("/writeAndReadsAndWrite")
    @Sharding
    public Object writeAndReadsAndWrite() {
        return testService.writeAndReadsAndWrite();
    }

    @ApiOperation("读 - 写 - 读")
    @GetMapping("/readAndWriteAndRead")
    @Sharding
    public Object readAndWriteAndRead() {
        return testService.readAndWriteAndRead();
    }

    @ApiOperation("读 - 写 - 写 - 读")
    @GetMapping("/readAndWritesAndRead")
    @Sharding
    public Object readAndWritesAndRead() {
        return testService.readAndWritesAndRead();
    }

    @ApiOperation("强制在写库读")
    @GetMapping("/forceReadInWrite")
    @Sharding
    public Object forceReadInWrite() {
        return testService.forceReadInWrite();
    }

    @ApiOperation("在@Select中insert")
    @GetMapping("/insertBySelect")
    @Sharding
    public Object insertBySelect() {
        return testService.insertBySelect();
    }

    @ApiOperation("在@Select中insert")
    @GetMapping("/insertBySelect2")
    @Sharding
    public Object insertBySelect2() {
        return testService.insertBySelect2();
    }

    @ApiOperation("nativeSql")
    @GetMapping("/nativeSql")
    @Sharding
    public Object nativeSql() {
        return testService.nativeSql();
    }

    @ApiOperation("测试")
    @GetMapping("/test")
    @Sharding
    public Object test() {
        return testService.test();
    }
}
